package javaClassExercise.valueTransport;

/**
 * Created by lomo on 2018.
 */
public class basicTypeTransport {


    public static void main(String ...args) {
        int x = 2;
        int y = 5;

        System.out.println("Values of x & y before modified: ");
        System.out.println(" x = " + x + " ; y = " + y);
        modifyBasicTypes(x ,y);
        System.out.println("Values of x & y after modified: ");
        System.out.println(" x = " + x + " ; y = " + y);
    }

    private static void modifyBasicTypes(int x, int y) {
        x = 10;
        y = 12;
    }
}

/**
 * 运行结果：
 *
 * Values of x & y before modified:
 * x = 2 ; y = 5
 * Values of x & y after modified:
 * x = 2 ; y = 5
 *
 * 分析：
 * x,y 是基本类型，存储在堆栈中，当调用modifyBasicTypes方法时，在堆栈中创建了这2个参数x和y的拷贝(假设称其为a,b)
 * 传递时是a和b被传递到方法中，所以原始的x和y参数并没有被传递到方法中，在方法中任何修改都只作用于拷贝的参数a,b
 *
 */